package com.yxjx.duoxue.payment;

import java.io.Serializable;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.yxjx.duoxue.BaseActionBarActivity;
import com.yxjx.duoxue.R;
import com.yxjx.duoxue.Yx;
import com.yxjx.duoxue.datamodel.DMOrder;
import com.yxjx.duoxue.utils.UIHelper;

public class PaymentFinishedPage extends BaseActionBarActivity {
	private DMOrder order;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.fragment_course_payment_ok);
		customizeActionBarTitle("购买成功");
		
	}
	
	@Override
	protected void onSaveInstanceState(Bundle outState) {
		super.onSaveInstanceState(outState);
		outState.putSerializable(Yx.KEY_ORDER_OBJECT, order);
	}
	
	@Override
	protected void onRestoreInstanceState(Bundle savedInstanceState) {
		super.onRestoreInstanceState(savedInstanceState);
		if (getIntent() == null) {
			return;
		} else {
			Serializable savedObject = savedInstanceState.getSerializable(Yx.KEY_ORDER_OBJECT);
			if (savedObject != null) {
				getIntent().putExtra(Yx.KEY_ORDER_OBJECT, savedObject);
			}
		}
	}
	
	@Override
	protected void onResume() {
		super.onResume();
		customizeUI();
	}

	private void customizeUI() {
		if (getIntent() == null || getIntent().getExtras() == null) {
			finish();
			return;
		}
		order = (DMOrder) getIntent().getExtras().getSerializable(Yx.KEY_ORDER_OBJECT);
		UIHelper.setText((TextView) findViewById(R.id.order_title), order.getProduct().getProductName());
		UIHelper.setText((TextView) findViewById(R.id.order_contact), order.getContactName());
		UIHelper.setText((TextView) findViewById(R.id.order_phone), order.getContactPhone());
	}
	
	public void viewOrder(View view) {
		if (order != null) {
			Intent intent = new Intent(getApplicationContext(), OrderInfoActivity.class);
			intent.putExtra(Yx.KEY_ORDER_ID, order.getId());
			startActivity(intent);
		}
	}
}
